home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-16 | 4.6 KB | 174 lines | [TEXT/????] |
- Newsgroups: comp.compilers.tools.pccts
- Path: gallant.apple.com!murky.apple.com!decwrl!pacbell.com!well!barrnet.net!agat
- e!howland.reston.ans.net!europa.eng.gtefsd.com!newsxfer.itd.umich.edu!zip.eecs.u
- mich.edu!umn.edu!parrt
- From: parrt@arc.umn.edu (Terence Parr)
- Subject: PCCTS 1.23 code gen fix
- Message-ID: <Cw5437.6As@news.cis.umn.edu>
- Sender: news@news.cis.umn.edu (Usenet News Administration)
- Nntp-Posting-Host: s13.arc.umn.edu
- Organization: AHPCRC, University of Minnesota, Minneapolis
- Date: Wed, 14 Sep 1994 22:05:58 GMT
- Lines: 159
-
- It turns out that I introduced this (...)* code-gen bug back in 1.20.
- I just happened to find it now. For example, the following didn't
- generate the right code:
-
- a : ( A | B )* A C ;
-
- Upon 'A C', a syntax error would occur.
-
- Terribly sorry. I'm in the process of adding parser exception handling
- so will probably not put out a new release just for this bug fix.
-
- Terence -------------------------------------
-
- To fix things, just change the following functions in gen.c (PS: I
- haven't had the time to test EVERYTHING with this fix. Use at your
- own risk ;).
-
- /*
- * Generate code for a loop blk of form:
- *
- * |---|
- * v |
- * --o-G-o-->o--
- */
- void
- #ifdef __STDC__
- genLoopBlk( Junction *begin, Junction *q, Junction *start, int max_k )
- #else
- genLoopBlk( begin, q, start, max_k )
- Junction *begin;
- Junction *q;
- Junction *start; /* where to start generating code from */
- int max_k;
- #endif
- {
- set f;
- int need_right_curly;
- require(q->ntype == nJunction, "genLoopBlk: not junction");
- require(q->jtype == aLoopBlk, "genLoopBlk: not loop block");
-
- if ( q->visited ) return;
- q->visited = TRUE;
- if ( q->p2 == NULL ) /* only one alternative? */
- {
- if ( DemandLookahead )
- if ( !GenCC ) {gen1("LOOK(%d);\n", max_k);}
- else gen1("look(%d);\n", max_k);
- gen("while ( ");
- if ( begin!=NULL ) genExpr(begin);
- else genExpr(q);
- /* if no predicates have been hoisted for this single alt (..)*
- * do so now
- */
- if ( ParseWithPredicates && begin->predicate==NULL )
- {
- Predicate *a = find_predicates((Node *)q->p1);
- if ( a!=NULL )
- {
- _gen("&&");
- genPredTree(a, q);
- }
- }
- _gen(" ) {\n");
- tabs++;
- TRANS(q->p1);
- if ( !GenCC ) gen1("zzLOOP(zztasp%d);\n", BlkLevel-1);
- if ( DemandLookahead )
- if ( !GenCC ) {gen1("LOOK(%d);\n", max_k);}
- else gen1("look(%d);\n", max_k);
- --tabs;
- gen("}\n");
- freeBlkFsets(q);
- q->visited = FALSE;
- return;
- }
- else gen("while ( 1 ) {\n");
- tabs++;
- if ( begin!=NULL )
- {
- if ( DemandLookahead )
- if ( !GenCC ) {gen1("LOOK(%d);\n", max_k);}
- else gen1("look(%d);\n", max_k);
- gen("if ( ");
- genExpr((Junction *)begin->p2);
- _gen(" ) break;\n");
- }
- f = genBlk(q, aLoopBlk, &max_k, &need_right_curly);
- set_free(f);
- freeBlkFsets(q);
-
- /* generate code for terminating loop (this is optional branch) */
- if ( begin==NULL ) gen("else break;\n"); /* code for exiting loop "for sure" */
-
- { int i; for (i=1; i<=need_right_curly; i++) {tabs--; gen("}\n");} }
- if ( !GenCC ) gen1("zzLOOP(zztasp%d);\n", BlkLevel-1);
- --tabs;
- gen("}\n");
- q->visited = FALSE;
- }
-
- /*
- * Generate code for a loop blk of form:
- *
- * |---|
- * v |
- * --o-->o-->o-G-o-->o--
- * | ^
- * v |
- * o-----------o
- *
- * q->end points to the last node (far right) in the blk. Note that q->end->jtype
- * must be 'EndBlk'.
- *
- * Generate code roughly of the following form:
- *
- * do {
- * ... code for alternatives ...
- * } while ( First Set of aLoopBlk );
- *
- * OR if > 1 alternative
- *
- * do {
- * ... code for alternatives ...
- * else break;
- * } while ( 1 );
- */
- void
- #ifdef __STDC__
- genLoopBegin( Junction *q )
- #else
- genLoopBegin( q )
- Junction *q;
- #endif
- {
- set f;
- int i;
- int max_k;
- require(q!=NULL, "genLoopBegin: invalid node and/or rule");
- require(q->ntype == nJunction, "genLoopBegin: not junction");
- require(q->jtype == aLoopBegin, "genLoopBegin: not loop block");
- require(q->p2!=NULL, "genLoopBegin: invalid Loop Graph");
-
- if ( GenLineInfo ) fprintf(output, LineInfoFormatStr, q->line, FileStr[q->file]);
-
- BLOCK_Preamble(q);
- BlkLevel++;
- f = First(q, 1, aLoopBegin, &max_k);
- /* If not simple LL(1), must specify to start at LoopBegin, not LoopBlk */
- if ( LL_k>1 && !set_nil(q->fset[2]) )
- genLoopBlk( q, (Junction *)q->p1, q, max_k );
- else genLoopBlk( q, (Junction *)q->p1, NULL, max_k );
-
- for (i=1; i<=CLL_k; i++) set_free(q->fset[i]);
- for (i=1; i<=CLL_k; i++) set_free(((Junction *)q->p2)->fset[i]);
- --BlkLevel;
- BLOCK_Tail();
- set_free(f);
- if (q->end->p1 != NULL) TRANS(q->end->p1);
- }
- ---------------------------------------------------------------------------
-